﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyWrite.API.Appicant.Command.Roles;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.Roles
{
    /// <summary>
    ///  [部门id]批量查询用户名称
    /// </summary>
    public class GetDepIdUserCommandHandler : IRequestHandler<GetDepIdUserCommand, APIResult<List<User>>>
    {
        private readonly IBaseRepository<User> userRepos;

        public GetDepIdUserCommandHandler(IBaseRepository<User> userRepos)
        {
            this.userRepos = userRepos;
        }


        public Task<APIResult<List<User>>> Handle(GetDepIdUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result = new APIResult<List<User>>();
            var list = userRepos.GetAll().Result.Where(x=> request.DepId.Contains(x.DepId.ToString()));
            if (list != null)
            {
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = list.ToList();
            }else
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
            }
            return Task.FromResult(result);
        }
    }
}
